﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Text.RegularExpressions;

namespace Shopfloormanagement.Forms
{
	public partial class scoreForm: DevExpress.XtraEditors.XtraForm
	{
		public static scoreForm instance = new scoreForm();
		public static string scoreDetail = "";
        public scoreForm()
		{
			instance = this;
            InitializeComponent();
		}
        public static string FormatToRtf(string text)
        {
            var htmlBuilder = new StringBuilder();

            // 添加基本样式
           //htmlBuilder.AppendLine("<style>");
           //htmlBuilder.AppendLine("body { font-family: '微软雅黑', sans-serif; font-size: 9pt; line-height: 1.5; }");
           //htmlBuilder.AppendLine("h3 { color: #333; margin-top: 15px; margin-bottom: 10px; }");
           //htmlBuilder.AppendLine("strong { color: #000; }");
           //htmlBuilder.AppendLine("ul { margin: 5px 0; padding-left: 20px; }");
           //htmlBuilder.AppendLine("li { margin: 3px 0; }");
           //htmlBuilder.AppendLine("</style>");

            // 处理标题
            text = Regex.Replace(text, @"###\s*(.*)", "<h3>$1</h3>");

            // 处理加粗文本
            text = Regex.Replace(text, @"\*\*(.*?)\*\*", "<strong>$1</strong>");

            // 处理列表项
            text = Regex.Replace(text, @"^\s*-\s*(.*)$", "<li>$1</li>", RegexOptions.Multiline);

            // 将连续的列表项包装在 ul 标签中
            text = Regex.Replace(text, @"(<li>.*?</li>\r?\n)+", "<ul>$0</ul>");

            // 处理空行
            //text = Regex.Replace(text, @"\r?\n\r?\n", "<br/><br/>");

            htmlBuilder.Append(text);

            return htmlBuilder.ToString();
        }
        private void scoreForm_Load(object sender, EventArgs e)
        {
			if (scoreDetail == "")
			{
				scoreDetail = "未能加载评分报告";
			}
			uiRichTextBox1.Text = FormatToRtf(scoreDetail);
        }
    }
}